package com.ly.mpayment.persist.service.ip;

import java.io.Serializable;
import java.util.HashMap;

import org.springframework.stereotype.Service;

import com.ly.mpayment.core.util.ListRange;
import com.ly.mpayment.persist.entity.IpSource;
import com.ly.mpayment.persist.service.AbstractService;

@Service
public class IpSourceServiceImpl extends AbstractService<IpSource, Serializable> implements IpSourceService {

	@Override
	public boolean saveIpSource(IpSource ip) {
		if(ip != null){
			this.saveOrUpdate(ip);
			return true;
		}
		return false;
	}

	@Override
	public IpSource findByIp(String ip) {
		return this.findUnique("select i from IpSource i where i.ip = ? ", ip);
	}

	@Override
	public IpSource findOne() {
		ListRange<IpSource> list = this.findPageDataByNamed("select i from IpSource i where i.stat = 1 order by i.createTime ", new HashMap<String, Object>(), 0, 3);
		return list == null ? null : list.getList().get(0);
	}

	@Override
	public boolean updateIpSource(IpSource ip) {
		if(ip != null){
			this.updateEntity(ip);
			return true;
		}
		return false;
	}

}
